package net.helpfulwebservices.cogitologopedia;

import net.helpfulwebservices.cogitologopedia.utility.GUI;
import net.helpfulwebservices.cogitologopedia.ws.wsConnectionTask;
import net.helpfulwebservices.cogitologopedia.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;



//http://www.mrwebmaster.it/mobile/guide/listener-ottimizzato-gestire-click-nostri-bottoni_1231.html
//http://stackoverflow.com/questions/9870164/creating-ksoap-request-with-properties-contaning-attributes

import android.view.View;
import android.widget.Button;
import android.widget.EditText;



public class Activity_login extends Activity {
    /** Called when the activity is first created. */
	private int _statusWs;

	
	
	/**
	 * @return the _statusWs
	 */
	public int getStatusWs() {
		return _statusWs;
	}



	/**
	 * @param i the _statusWs to set
	 */
	public void setStatusWs(int i) {
		this._statusWs = i;
	}



	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

    }	
	
	
    public void bttLogin_onClick(View view) 
    {
    	Resources res = getResources();
    	Log.v(res.getString(R.string.app_name), "bttLogin_onClick: " + view.toString());
    	
    	EditText txtUsername = (EditText) this.findViewById(R.id.txtUsername);
    	EditText txtPassword = (EditText) this.findViewById(R.id.txtPassword);
    	Button buttonLogin = (Button) this.findViewById(R.id.bttLogin);
    	Button buttonbttClear = (Button) this.findViewById(R.id.bttClear);
    	
    	
    	if (txtUsername.getText().length()<=0){
    		GUI.messageBox(this,"Avviso","Bisogna compilare tutti i campi.",R.drawable.warning);
    	}else if(txtPassword.getText().length()<=0){
    		GUI.messageBox(this,"Avviso","Bisogna compilare tutti i campi.",R.drawable.warning);
    	}else{
    	
    		wsConnectionTask _wsConnectionTask=new wsConnectionTask(this,this);
    		_wsConnectionTask.execute(
    				txtUsername.getText().toString(),
    				txtPassword.getText().toString(),
    				res.getString(R.string.ws_namespace),
    				res.getString(R.string.ws_method_accountinfo),
    				res.getString(R.string.ws_url),
    				res.getString(R.string.ws_soap_action_accountinfo)
    				);
    		
    		buttonLogin.setEnabled(false);
    		buttonbttClear.setEnabled(false);
    	}
    	
    }
    
	
    public void bttClear_onClick(View view) {
    	((EditText) findViewById(R.id.txtUsername)).setText("");
    	((EditText) findViewById(R.id.txtPassword)).setText("");
    }

    
    
    
}